package com.bigger.arch.app.web.controller;

import com.bigger.arch.app.biz.IUserBiz;
import com.bigger.arch.app.repository.model.UserModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.math.BigDecimal;
import java.util.List;

@Controller
@RequestMapping("/user")
public class UserController {
    @Autowired
    private IUserBiz userBiz;

    @ResponseBody
    @RequestMapping("/getItem")
    public UserModel getItem(Integer id) {
        return userBiz.getItem(id);
    }

    @ResponseBody
    @RequestMapping("/getItems")
    public List<UserModel> getItems() {
        return userBiz.getItems();
    }

    @RequestMapping(path = "/saveItem", method = RequestMethod.POST)
    public String saveItem(UserModel userModel) {
        Boolean flag = userBiz.saveItem(userModel);
        return "redirect:/demo/index";
    }

    @ResponseBody
    @RequestMapping("/getCount")
    public String getCount() {
        return "获取用户总数：" + userBiz.getCount();
    }

    @RequestMapping(path = "/transferAccount", method = RequestMethod.POST)
    public String transferAccount(@RequestParam String fromName,
                                  @RequestParam String toName,
                                  @RequestParam BigDecimal balance) {
        Boolean flag = userBiz.transferAccount(fromName, toName, balance);
        return "redirect:/demo/index";
    }
}
